package com.hfh.net;

import org.junit.Test;

import javax.naming.ldap.SortKey;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

import java.util.Scanner;

/**
 * @Author hfh
 * @Date 2022 09 13 16 03
 **/
public class Test3 {
    @Test
    public void client() throws IOException {
        Socket s = new Socket(InetAddress.getLocalHost(),9999);
        OutputStream os = s.getOutputStream();

        Scanner scan = new Scanner(System.in);
        while (true){
            String str = scan.next();
            os.write(str.getBytes());
        }








    }

    @Test
    public void server() throws IOException {
        ServerSocket ss = new ServerSocket(9999);
        Socket s = ss.accept();
        InputStream is = s.getInputStream();

        while (true){
            byte[] arr = new byte[1024];
            int len;
            while ((len= is.read(arr))!=-1){
                System.out.println(new String(arr, 0, len));
            }
        }
    }
}
